from rest_framework import viewsets
from rest_framework.viewsets import ModelViewSet, ReadOnlyModelViewSet
from rest_framework import mixins
from rest_framework.permissions import IsAuthenticated

from Apps.Article.serializers import *
from Apps.Article.models import *
from .utils.pagination import ArticlePagination
from Apps.utils.permissions import IsOwnerOrReadOnly
from ..utils.authentication import AccessAuthentication


class CategoryViewSet(ModelViewSet):
    """
    List:
        文章分类列表数据
    """
    queryset = Category.objects.all()
    serializer_class = CategorySerializer


class TagViewSet(ModelViewSet):
    """
    List:
        文章标签列表数据
    """
    queryset = Tag.objects.all()
    serializer_class = TagSerializer


class ArticleViewSet(ReadOnlyModelViewSet):
    """文章"""
    queryset = Article.objects.all().order_by('id')
    serializer_class = ArticleSerializer
    pagination_class = ArticlePagination
    authentication_classes = (AccessAuthentication,)


class CreateArticleViewSet(mixins.CreateModelMixin, mixins.UpdateModelMixin, mixins.RetrieveModelMixin,
                           viewsets.GenericViewSet):
    serializer_class = CreateArticleSerializer
    queryset = Article.objects.all()
    permission_classes = (IsAuthenticated, IsOwnerOrReadOnly)


class CommentViewSet(ModelViewSet):
    """评论"""
    queryset = Comment.objects.all().order_by('id')
    serializer_class = CommentSerializer
